import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';


import 'kq_swipe_item.dart';

/// KqSwipeDeleteItem 左滑删除（列表）项
///
/// 本控件为KqSwipeItem的应用示例
/// 在控件上左滑时，显示右侧的删除按钮
/// 注意：本控件仅起到示例作用，勿在实际项目中使用
class KqSwipeDeleteItem extends StatefulWidget {
  const KqSwipeDeleteItem({super.key});

  @override
  State<StatefulWidget> createState() {
    return _KqSwipeDeleteItemState();
  }
}

class _KqSwipeDeleteItemState extends State<KqSwipeDeleteItem> {
  @override
  Widget build(BuildContext context) {
    return Center(
      child: Container(
          alignment: Alignment.center,
          height: 24,
          child: KqSwipeItem(
              mainWidget: GestureDetector(
                onTap: () {
                  debugPrint("kqSwipeItem :: ItemPressed");
                },
                child: _buildItem(),
              ),
              actionsWidth: 48,
              actionList: <Widget>[_buildDeleteButton()])),
    );
  }

  Widget _buildItem() {
    return Container(
      alignment: Alignment.centerLeft,
      height: 24,
      color: Color(0xFFFFFFFF),
      child: Text(
        "     主站#001            左滑删除控件测试                                              离线",
        style: TextStyle(fontSize: 12 ),
      ),
    );
  }

  Widget _buildDeleteButton() {
    return GestureDetector(
      onTap: () {
        debugPrint("kqSwipeItem :: DeleteButtonPressed");
      },
      child: Container(
        alignment: Alignment.center,
        height: 22,
        width: 48,
        color: Color(0xFFEE3E3E),
        child: Text(
          "删除",
          style: TextStyle(fontSize: 12, color: Color(0xFFFFFFFF)),
        ),
      ),
    );
  }
}
